package com.dev.op.controller;


import com.dev.op.VO.ResultVO;
import com.dev.op.entity.Tag;
import com.dev.op.service.ProblemTagService;
import com.dev.op.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/problems/tags")
@PreAuthorize("hasAnyRole('admin','student','teacher')")
public class ProblemTagController {

    @Autowired
    ProblemTagService problemTagService;


    @GetMapping("/{id}")
    public ResultVO<List<Tag>> getProblemTags(@PathVariable String id) {
        return ResultVO.success(problemTagService.getTagsByProblemId(id));
    }

    @PreAuthorize("hasAnyRole('admin')")
    @PutMapping("/{id}")
    public ResultVO<Boolean> updateProblemTags(@PathVariable String id, @RequestBody List<Tag> tags) {
        return ResultVO.success(problemTagService.updateProblemTag(id,tags));
    }
}
